<?php

namespace app\admin\model\shop\advert;

use think\Model;

/**
 * NoticeBar
 */
class NoticeBar extends Model
{
    // 表名
    protected $name = 'shop_advert_notice_bar';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    /**
     * 添加后
     * @param $model
     * @return void
     */
    protected static function onAfterInsert($model): void
    {
        if ($model->weigh == 0) {
            $pk = $model->getPk();
            if (strlen($model[$pk]) >= 19) {
                $model->where($pk, $model[$pk])->update(['weigh' => $model->count()]);
            } else {
                $model->where($pk, $model[$pk])->update(['weigh' => $model[$pk]]);
            }
        }
    }

    public function getContentAttr($value): string
    {
        return !$value ? '' : htmlspecialchars_decode($value);
    }
}